Welcome to Python Style Guide and Coding Practices. After watching this video, you'll be able to Describe the importance of writing readable code List the Python coding conventions Explain static code analysis When you write code, you need to ensure the team can read and understand it easily. This task requires some coding standards and conventions. Python.org has released a document called Python Enhancement Proposal 8, or PEP-8, that provides conventions and guidelines to make your Python code readable and consistently formatted. Let's start with the key guidelines for improving the readability of the code. PEP-8 recommends the use of spaces instead of tabs for indentation. Wondering why? Text editors and Integrated Development Environments, or IDEs, interpret the number of spaces in a tab differently. For example, one editor might interpret a tab as three spaces, while another might interpret it as four. Using a tab for indentation can lead to non-uniformity in code, resulting in formatting errors. For example, observe the spacing difference when tab is pressed for statement 1 for the if condition under editor 1 when compared with the space before statement 1 for the if condition under editor 2. To avoid such errors, you should use a consistent number of spaces when indenting your code. For uniformity, the guideline is to use four spaces for every indentation level in a code. Four spaces for an indentation are sufficient for appropriate readability. Please note that the four dots have been added before statement 1 and statement 2 to depict four spaces. PEP-8 also recommends using blank lines to separate functions and classes in the code. Notice that in the left block, which does not follow PEP-8 guidelines, there is no space between where function 1 ends and where class UserClass, capital U and capital C, no space. However, the right side shows the correct representation with a space before the class definition. The blank lines help establish the beginning and end of different parts of the code. To improve code readability, use spaces around operators and after commas. Using spaces will make the commands look spacious and discreet, improving command readability. Let's look at some examples. When you write A equals B plus C without any spaces, it can be confusing. However, when you add the spaces, for example, A space equals space B space plus space C, readability improves. Next, let's look at some coding conventions to maintain consistency and manageability. A key coding convention is to create separate functions for functionalities with larger blocks of code. You can then call the functions from the main program. For example, in the code, the if-else syntax does not have a function and will need to be written every time you need the functionality. However, if you notice function underscore one written as def function underscore one with two parameters A and B, it can be called easily. For example, C equals function one A comma B. This increases the execution speed of the code and supports the reuse of the code block in a much more convenient way. Another coding convention is to name the functions and files using lowercase with underscores. Wondering why? Python uses the naming convention and has many built-in libraries and predefined functions that use the common naming conventions. Therefore, using a lowercase function name, preferably with underscores, is advisable to make the functions unique. For example, instead of writing function name as comp surface with capital S, radiation with capital R, write comp underscore surface underscore radiation. An exception to the rule is the naming criteria for Python packages, where underscores are generally discouraged. For example, instead of writing my underscore package, write my package. Naming the classes using camel case is also a coding convention. Camel case, or the cap word case, is a naming convention for classes that is well accepted in the coding community. Camel case also helps distinguish between classes and functions in the code. For example, instead of writing class lamb underscore squirrel underscore cage, the best practice is to name the class as lamb squirrel cage with the initial L, S, and C in capital letters. Use the coding convention of capitalizing all words and separating them with underscores for consistency. The name usually indicates the constant's purpose. For example, max file upload size in capital letters. We discussed the coding convention and guidelines. Software developers commonly use static code analysis to manage compliance with these style guidelines. Static code analysis is a method to evaluate code against a predefined style and standard without executing the code. Static analysis helps find issues such as programming errors, coding standard violations, undefined values, syntax violations, and security vulnerabilities. You can use the PyLint library to check the compliance of your Python code with PEP 8 guidelines. In this video, you learned that writing consistent code helps all team members read and understand the code easily. The PEP 8 guidelines for better code readability include the following. Four spaces for indentation. Use blank lines to separate functions and classes. And use spaces around operators and after commas. Some coding conventions for code consistency and manageability include add larger blocks of code inside functions. Name functions and files using lowercase with underscores. Name classes using camel case. And name constants in all capital letters with underscores separating words. Use static code analysis method to evaluate your code against a predefined style and standard without executing the code.